import IPython.core.display as di
# This line will hide code by default when the notebook is exported as HTML
di.display_html('<script>jQuery(function() {if (jQuery("body.notebook_app").length == 0) { jQuery(".input_area").toggle(); jQuery(".prompt").toggle();}});</script>', raw=True)
# This line will add a button to toggle visibility of code blocks, for use with the HTML export version
#di.display_html('''<button onclick="jQuery('.input_area').toggle(); jQuery('.prompt').toggle();">Toggle code</button>''', raw=True)
import pandas as pd
import numpy as np
import plotly
import cufflinks as cf
from plotly.graph_objs import Scatter, Layout
import summary_functions as scf
plotly.offline.init_notebook_mode()
cf.set_config_file(offline=True, world_readable=True, theme='ggplot')
input_file = 'network_summary_detailed.xlsx'
screenline_dict = {'Primary': {
4: 'Tacoma - East of CBD',
14: 'Auburn',
15: 'Auburn',
22: 'Tukwila',
23: 'Renton',
29: 'Seattle - South of CBD',
30: 'Bellevue/Redmond',
32: 'TransLake',
35: 'Ship Canal',
37: 'Kirkland/Redmond',
41: 'Seattle - North',
43: 'Lynnwood/Bothell',
44: 'Bothell',
46: 'Mill Creek'},
'Secondary': {
2: 'Parkland',
3: 'Puyallup',
7: 'Tacoma Narrows',
18: 'Maple Valley',
19: 'SeaTac',
20: 'Kent',
54: 'Gig Harbor',
57: 'Kitsap - North',
58: 'Agate Pass',
60: 'Cross-Sound',
66: 'Preston, Issaquah',
71: 'Woodinville'}}
observed_screenline_volumes = {'Tacoma - East of CBD': 271777,
'Auburn': 534811,
'Tukwila': 239527,
'Renton': 81758,
'Seattle - South of CBD': 490806,
'Bellevue/Redmond': 354612,
'TransLake': 250220,
'Ship Canal': 521155,
'Kirkland/Redmond': 381331,
'Seattle - North': 327021,
'Lynnwood/Bothell': 231368,
'Bothell': 255590,
'Mill Creek': 350492,
'Parkland': 285859,
'Puyallup': 118726,
'Tacoma Narrows': 79000,
'Maple Valley': 61921,
'SeaTac': 71364,
'Kent': 504607,
'Gig Harbor': 58503,
'Kitsap - North': 97177,
'Agate Pass': 21000,
'Cross-Sound': 17466,
'Preston, Issaquah': 93227,
'Woodinville': 98331}
# primary screenline plot
screenline_df = pd.read_excel(input_file,sheetname='Screenline Volumes')
screenline_type = 'Primary'
screenline_df['Screenline Name'] = screenline_df['Screenline'].map(screenline_dict[screenline_type])
screenline_df = screenline_df.groupby('Screenline Name').sum()
screenline_df.loc['Auburn', 'Screenline'] = '14/15'
screenline_df = screenline_df.dropna()
screenline_df = screenline_df.reset_index()
screenline_df['Observed Volume'] = screenline_df['Screenline Name'].map(observed_screenline_volumes)
screenline_df = screenline_df.set_index('Screenline Name')
screenline_df['Modeled Volume'] = screenline_df['Volumes']
del screenline_df['Volumes']
screenline_df = screenline_df[['Screenline', 'Modeled Volume', 'Observed Volume']]
screenline_df['Est/Obs'] = (screenline_df['Modeled Volume']/screenline_df['Observed Volume']).round(2)
screenline_df_primary = scf.get_differences(screenline_df, 'Modeled Volume', 'Observed Volume', -2)
screenline_df_primary
screenline_df_primary[['Modeled Volume','Observed Volume']].iplot(kind='bar',title='Model vs. Observed counts by Primary Screenline',
xTitle='Primary Screeline',yTitle='Counts')
# secondary screenline plot
screenline_df = pd.read_excel(input_file,sheetname='Screenline Volumes')
screenline_type = 'Secondary'
screenline_df['Screenline Name'] = screenline_df['Screenline'].map(screenline_dict[screenline_type])
screenline_df = screenline_df.groupby('Screenline Name').sum()
screenline_df.loc['Auburn', 'Screenline'] = '14/15'
screenline_df = screenline_df.dropna()
screenline_df = screenline_df.reset_index()
screenline_df['Observed Volume'] = screenline_df['Screenline Name'].map(observed_screenline_volumes)
screenline_df = screenline_df.set_index('Screenline Name')
screenline_df['Modeled Volume'] = screenline_df['Volumes']
del screenline_df['Volumes']
screenline_df = screenline_df[['Screenline', 'Modeled Volume', 'Observed Volume']]
screenline_df['Est/Obs'] = (screenline_df['Modeled Volume']/screenline_df['Observed Volume']).round(2)
screenline_df_secondary = scf.get_differences(screenline_df, 'Modeled Volume', 'Observed Volume', -2)
screenline_df_secondary
screenline_df_secondary[['Modeled Volume','Observed Volume']].iplot(kind='bar',title='Model vs. Observed counts by Secondary Screenline',
xTitle='Secondary Screeline',yTitle='Counts')